package com.study.common;

import com.alibaba.druid.filter.stat.StatFilter;
import com.alibaba.druid.wall.WallFilter;
import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.activerecord.SqlReporter;
import com.jfinal.plugin.druid.DruidPlugin;
import com.jfinal.template.Engine;
import com.study.controller.HelloController;
import com.study.controller.UserController;
import com.study.intercept.ExceptionInterceptor;
import com.study.intercept.LoggerInterceptor;
import com.study.model.UserInfo;
/**
 * @description JFinalCommonConfig
 * @author TDW
 * @date 2018年10月9日
 *
 */

public class JFinalCommonConfig extends JFinalConfig {

	//常量
	public void configConstant(Constants me) {
		loadPropertyFile("db.properties");//加载属性文件
		me.setDevMode(true);

	}

	//url 路由
	public void configRoute(Routes me) {
		me.add("/hello", HelloController.class);
		me.add("/user", UserController.class);

	}
	
	//插件
	public void configPlugin(Plugins me) {
		DruidPlugin dp = new DruidPlugin(getProperty("jdbc.url"),
				getProperty("jdbc.user"), getProperty("jdbc.pwd"));
		dp.addFilter(new StatFilter());
		WallFilter wall = new WallFilter();
		wall.setDbType("mysql");
		dp.addFilter(wall);
		dp.setFilters("stat");
		me.add(dp);
		ActiveRecordPlugin arp = new ActiveRecordPlugin(dp);

		arp.setShowSql(true);
		SqlReporter.setLog(true);
		// com.jfiactionreport
		me.add(arp);
		// 定时任务插件
//		me.add(new QuartzPlugin());

		// orm映射
		arp.addMapping("user", UserInfo.class);
	}

	//全局拦截器
	public void configInterceptor(Interceptors me) {
		me.add(new ExceptionInterceptor());//xxxInterceptor extends  com.jfinal.aop.Interceptor;
		me.add(new LoggerInterceptor());
	}

	public void configHandler(Handlers me) {
	}

	@Override
	public void configEngine(Engine arg0) {
		
	}
}
